home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / tutor / asm1tut.exe / CHAP14.DOC < prev    next >
Text File  |  1990-07-19  |  8KB  |  156 lines

  1.  
  2.  
  3.  
  4.                                                                            134
  5.  
  6.                                  CHAPTER 14 - ZOOM
  7.  
  8.  
  9.              There are only a couple of reasons for working at the assembler
  10.              level. Perhaps you're curious about how the PC functions at the
  11.              machine level. Maybe you want to optimize a time consuming
  12.              section of code. Maybe you want to work easily with the DOS
  13.              function calls and the BIOS calls (which will be introduced in a
  14.              later chapter). Or maybe you want raw speed. 
  15.  
  16.              Every time that I enter:
  17.  
  18.                  >dir /w
  19.  
  20.              and watch DOS meander its way down the screen at a leisurely
  21.              pace, I think "Can't the computer go any faster?"  Let's find
  22.              out. This is going to be a short chapter. Make a copy of
  23.              template.asm, and we'll call it zoom.asm. This is going to
  24.              overwrite the entire screen 200 times.{1} 
  25.  
  26.              Before we write to the screen, we need to know where the screen
  27.              is. When IBM designed the structure of the PC, they decided to
  28.              put the memory for the monochrome card in one place and the
  29.              memory for the color card in another place - apparently they
  30.              thought you might want to have both a color monitor and a
  31.              monochrome monitor running at the same time. The color monitor is
  32.              in segment 0B800 at offset 0, and the monochrome monitor is in
  33.              segment 0B000 at offset 0. We need to put the correct number into
  34.              the program, so you need to know whether you have a color card or
  35.              a monochrome card. If one segment number doesn't work, you can
  36.              try the other.
  37.  
  38.              TEMPLATE.ASM 
  39.              ; - - - - - - - - - -  START CODE BELOW THIS LINE
  40.                     call  show_regs_and_wait  ; {2}
  41.                                               ; we are about to start 
  42.                                               ; this marks the time
  43.  
  44.                     mov   ax, 0B800h       ; color seg. 0B000h is mono seg
  45.                     mov   es, ax           ; es is at video card segment
  46.                     mov   cx, 2            ; do this whole thing twice
  47.              outer_loop:
  48.              ____________________
  49.  
  50.                 1 It is now time for you to go out and get a book about the
  51.              internal structure and i/o interface of the PC. One good book is
  52.              "The Peter Norton Programmer's Guide To The IBM PC", by guess
  53.              who? It is clearly written and a good introduction. Another
  54.              quality book is "DOS Programmer's Reference" by Terry Dettmann.
  55.              It is very systematically laid out and is more techie oriented.
  56.  
  57.                 2 We need to initialize the video card to make sure it is in
  58.              the right place. This is the easiest way. The registers
  59.              themselves mean nothing to us.
  60.  
  61.              ______________________
  62.  
  63.              The PC Assembler Tutor - Copyright (C) 1989 Chuck Nelson
  64.  
  65.  
  66.  
  67.  
  68.              Chapter 14 - Zoom                                             135
  69.              _________________
  70.  
  71.                     push  cx               ; save for outer loop instruction
  72.                     mov   cx, 100          ; 100 repeats ; zoom_loop count
  73.                     mov   al, '0'          ; 100 characters starting at '0' 
  74.                     mov   ah, 07h          ; black background, white letters 
  75.               
  76.              zoom_loop:    ; draw the screen 100 times 
  77.                     push  cx 
  78.                     mov   cx, 2000         ; 80 X 25 screen is 2000 words long
  79.                     mov   si, 0            ; start at offset 0000. 
  80.               
  81.              inner_loop:    ; inner loop - fill the screen - 2000 words
  82.                     mov   es:[si], ax 
  83.                     add   si, 2 
  84.                     loop  inner_loop 
  85.               
  86.                     inc   al               ; next higher ASCII character  
  87.                     pop   cx               ; zoom_loop count
  88.                     loop  zoom_loop 
  89.  
  90.                     pop   cx               ; outer_loop count
  91.                     loop  outer_loop
  92.  
  93.                     call  get_continue     ; finished - this is for timing 
  94.              ; - - - - - - - - - - END CODE ABOVE THIS LINE
  95.  
  96.  
  97.              Show_regs_and_wait resets the video card, so we use it to make
  98.              sure the video memory is set at offset 0000. It then waits for
  99.              ENTER. At the end, get_continue waits for ENTER.{3} This way you
  100.              can mark the beginning and the end in order to time it. We set
  101.              the ES segment to the video segment. This is different depending
  102.              on whether you have a monochrome card or a color card. The
  103.              monochrome segment is at 0B000h and the color card is at 0B800h.
  104.              You need to know which kind of card you have so you can put the
  105.              right number into ES via AX. 
  106.  
  107.              Since the normal segment for SI is the DS segment, we need to put
  108.              in a segment override to use SI with the ES segment.
  109.  
  110.              We start with the ASCII character '0' and then do the next 99
  111.              characters in increasing ASCII sequence. Technically, ASCII
  112.              characters end at 127, but the PC extended characters go up to
  113.              255, so we will start with ASCII 48d and end with ASCII 147d. The
  114.              zoom_loop changes the character 100 different times, and the
  115.              inner_loop fills the screen. That 07h in AH means that we will
  116.              have white characters on a black background. The outer loop has a
  117.              count of 2. This should be adjusted. If you have a medium speed
  118.              machine make it 4 (400 screen fills) and if you have a high speed
  119.              machine make it 8 (800 screen fills).
  120.  
  121.              ____________________
  122.  
  123.                 3 That is its mission in life. It is there so that you can
  124.              time blocks of code. If you want to find out how long some code
  125.              takes, repeat it 10,000  (or whatever is appropriate) times and
  126.              put  get_continue in front of it and behind it. That way you can
  127.              control the start and mark the finish.
  128.  
  129.  
  130.  
  131.  
  132.              The PC Assembler Tutor                                        136
  133.              ______________________
  134.  
  135.              When this is done, the screen will be filled with characters so
  136.              you will need to use the DOS command
  137.  
  138.                  > cls
  139.  
  140.              to clear the screen for anything else.
  141.  
  142.              When it is all assembled and linked, get a cup of coffee and a
  143.              wristwatch with a second hand and we'll time it. Divide by 200
  144.              (or 400 or 800) to find out how long it takes to fill one screen.
  145.              If the characters are not on your screen, you probably have the
  146.              wrong segment address for your video card, so try the other one.
  147.              Are you ready to time it? Then ready, set, go.
  148.  
  149.              Hmmm. On my machine 200 repeats takes about 4 seconds, while the
  150.              dir command takes about 1 second for one screen. That means that
  151.              zoom.asm is about 50 times faster. That's the difference between
  152.              someone running a 4 minute mile and someone running a 3hr. 20min.
  153.              mile. This is one of the reasons people like to work at the
  154.              assembler level.
  155.  
  156.